package com.xsmart.oa.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
/**
 * 分销商管理
 *
 * @author xxf
 * @date 2018/2/6
 */
@Component
public interface DistributorManageDAO {

    /**
    * 查询所有分销商
    *
    * @author xxf
    * @date 2018/2/6
    */
    @Select("<script>"+
            " select m.user_id,m.is_validated,i.phone,s.id shop_id ,i.user_name, "+
            " s.shop_name,s.shop_title,s.shop_address,s.seller_email,s.kf_qq,s.kf_ww,s.kf_tel,s.mobile,s.notice,s.status, "+
            " DATE_FORMAT(i.check_time,'%Y-%m-%d %T')check_time ,"+
            " (select count(*) from goods g where g.goods_id in (select goods_id from user_seller_goods where id=s.id))in_seller, "+
            " (select count(*) from goods g where g.goods_id not in(select goods_id from user_seller_goods where id=s.id ))no_in_seller "+
            " from infs_user m "+
            " left join infu_user_request_type_task i on m.user_id=i.user_id "+
            " left join seller_shopinfo s on m.user_id=s.ru_id "+
            "<where>"+
            " m.user_type=1 "+
            " <if test=\"distributorPhone != null and distributorPhone != ''\">and i.Phone = #{distributorPhone} </if> "+
            " <if test=\"distributorName != null and distributorName != ''\">and s.shop_name like concat('%',#{distributorName},'%') </if> "+
            "</where>"+
            "</script>")
    List<Map<String,Object>> queryDistributor(Pagination pagination, @Param("distributorPhone") String distributorPhone, @Param("distributorName") String distributorName);

    /**
     * 分销商信息修改-1.通过ID修改分销商表
     *
     * @author xxf
     * @date 2018/2/7
     * */
    @Update("update infs_user set is_validated=#{is_validated} where user_id=#{user_id}")
    int updateDistributor(@Param("user_id") Integer user_id, @Param("is_validated") Integer is_validated);

    /**
     * 分销商信息修改-2.通过ID修改分销商申请表中的电话号码名
     *
     * @author xxf
     * @date  2018/2/7
     * */
    @Update("update infu_user_request_type_task set phone=#{phone} where user_id=#{user_id}")
    int updateRequestInfo(@Param("user_id") Integer user_id, @Param("phone") String phone);

    /**
     * 店铺信息修改
     *
     * @author xxf
     * @date 2018/3/5
     */
    @Update("update seller_shopinfo set shop_name=#{shopInfo.shop_name},shop_title=#{shopInfo.shop_title}, "+
    "shop_address=#{shopInfo.shop_address},seller_email=#{shopInfo.seller_email},mobile=#{shopInfo.mobile},notice=#{shopInfo.notice}, "+
    "status=#{shopInfo.status} where id=#{shopInfo.shop_id}")
    int updateShopInfo(@Param("shopInfo") Map shopInfo);
}
